package com.pureut.storage.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.storage.dto.PickingPurchaseDto;
import com.pureut.storage.service.PickingPurchaseService;
import com.pureut.storage.vo.OrderReviewVo;
import com.pureut.storage.vo.PickingPurchaseVo;
import com.pureut.storage.vo.PickingRestDbVo;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/** 采购退货控制层
 * @author: CM
 * @date: 2022/12/30  11:26
 */

@RestController
@RequestMapping("/pickingPurchase")
public class PickingPurchaseController extends BaseController {

    @Resource
    private PickingPurchaseService pickingPurchaseService;

    /**
     * 新增采购退货单
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:add")
    @Log(title = "新增采购退货单", businessType = BusinessType.INSERT)
    @PostMapping("/addPurchase")
    public R<Void> addPurchase(@RequestBody PickingPurchaseVo pickingPurchaseVo) throws Exception {
        return toAjax(pickingPurchaseService.addPurchase(pickingPurchaseVo));
    }



    /**
     * 关结采购退货单
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:close")
    @Log(title = "关结采购退货单", businessType = BusinessType.UPDATE)
    @PostMapping("/closePurchase")
    public R<Void> closePurchase(@RequestBody PickingPurchaseVo pickingPurchaseVo) throws Exception {
        return toAjax(pickingPurchaseService.closePurchase(pickingPurchaseVo));
    }

    /**
     * 拣货提示
     */
    @GetMapping("/point/{id}")
    public R<?> point(@PathVariable("id") Long id) throws Exception {
        return R.ok(pickingPurchaseService.point(id));
    }


    /**
     * 修改采购退货单
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:edit")
    @Log(title = "修改采购退货单", businessType = BusinessType.UPDATE)
    @PostMapping("/updatePurchase")
    public R<Void> updatePurchase(@RequestBody PickingPurchaseVo pickingPurchaseVo) throws Exception {
        return toAjax(pickingPurchaseService.updatePurchase(pickingPurchaseVo));
    }

    /**
     * 删除单据
     */
   //@SaCheckPermission("warehouse:outbound:purreturn:remove")
    @Log(title = "删除采购退货单", businessType = BusinessType.DELETE)
    @DeleteMapping("/deletePurchase/{ids}")
    public R<Void> deletePurchase(@PathVariable("ids") String ids) throws Exception {
        return toAjax(pickingPurchaseService.deletePurchase(ids));
    }

    /**
     * 查看单据
     */
   //@SaCheckPermission("warehouse:outbound:purreturn:query")
    @GetMapping("/view/{id}")
    public R<?> view(@PathVariable("id") Long id) throws Exception {
        return R.ok(pickingPurchaseService.view(id));
    }

    /**
     * 查看单据列表
     */
    @GetMapping("/list")
    public TableDataInfo<PickingPurchaseDto> getList(PickingPurchaseVo pickingPurchaseVo, PageQuery pageQuery) throws Exception {
        //查询采购退货列表
        return pickingPurchaseService.getList(pickingPurchaseVo,pageQuery);

    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:submit")
    @Log(title = "提交采购退货单审核", businessType = BusinessType.UPDATE)
    @GetMapping("/submitPurchase/{ids}")
    public R<Void> submitPurchase(@PathVariable("ids") String ids) throws Exception {
        return toAjax(pickingPurchaseService.submitPurchase(ids));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("warehouse:outbound:shipsale:quash")
    @Log(title = "撤销审核", businessType = BusinessType.UPDATE)
    @GetMapping("/revoke/{ids}")
    public R<Void> revoke(@PathVariable("ids") String ids) throws Exception {
        return toAjax(pickingPurchaseService.revoke(ids));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:examine")
    @Log(title = "审核采购退货单据", businessType = BusinessType.UPDATE)
    @PutMapping("/purchaseReview")
    public R<Void> purchaseReview(@Validated @RequestBody OrderReviewVo orderReviewVo) throws Exception {
        return toAjax(pickingPurchaseService.purchaseReview(orderReviewVo));
    }



    /**
     * Pda出库
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:outbound")
    @Log(title = "采购退货Pda出库", businessType = BusinessType.UPDATE)
    @PostMapping("/outPurchase")
    public R<?> outPurchase(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(pickingPurchaseService.outPurchase(pickingRestDbVo));
    }

    /**
     * 采购退货拣货完成
     */
    @GetMapping("/finishProduction/{id}")
    public R<Void> finishProduction(@PathVariable("id") Long id) throws Exception {
        return toAjax(pickingPurchaseService.subcontractingPurchase(id));
    }


    /**
     * 采购退货交接
     */
    //@SaCheckPermission("warehouse:outbound:purreturn:handover")
    @Log(title = "采购退货交接", businessType = BusinessType.UPDATE)
    @PostMapping("/purchaseHandover")
    public R<?> purchaseHandover(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(pickingPurchaseService.purchaseHandover(pickingRestDbVo));
    }


}
